﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace TextEmbedding.Core
{
    

    public static class TextCollectionConverter
    {
        /// <summary>
        /// 将多种文本集合类型转换为 List<string>
        /// </summary>
        public static List<string> ToStringList(object input)
        {
            if (input == null) return new List<string>();

            switch (input)
            {
                case string str: // 单个字符串
                    return new List<string> { str };

                case string[] arr:
                    return arr.ToList();

                case List<string> list:
                    return list;

                case ArrayList arrayList:
                    return arrayList.Cast<object>()
                                    .Select(o => o?.ToString() ?? "")
                                    .ToList();

                case JArray jArray:
                    return jArray.Select(t => t.ToString()).ToList();

                case IEnumerable enumerable: // 泛型 IEnumerable, 包含 List<object>等
                    return enumerable.Cast<object>()
                                     .Select(o => o?.ToString() ?? "")
                                     .ToList();

                default:
                    throw new ArgumentException($"Unsupported input type: {input.GetType()}");
            }
        }
    }

}
